package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachPlanDto;
import com.xuecheng.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "课程计划编辑接口")
@RestController
@RequiredArgsConstructor
public class TeachPlanController {

    private final TeachPlanService teachPlanService;

    /**
     * 查询课程计划
     *
     * @param courseId
     * @return
     */
    @ApiOperation("查询课程计划树形结构")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachPlanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachPlanService.findTeachplanTree(courseId);
    }

    /**
     * 新增或修改课程计划
     *
     * @param teachplan 课程计划
     */
    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplan) {
        teachPlanService.saveTeachplan(teachplan);
    }

    /**
     * 删除课程计划
     *
     * @param id 课程计划id
     */
    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id) {
        teachPlanService.deleteTeachplan(id);
    }

    /**
     * 移动课程计划
     *
     * @param id   课程计划id
     * @param move 移动的类型 是上移还是下移
     */
    @ApiOperation("移动课程计划上移下移")
    @PostMapping("/teachplan/{move}/{id}")
    public void moveTeachplan(@PathVariable("id") Long id, @PathVariable("move") String move) {
        teachPlanService.moveTeachplan(id, move);
    }

    /**
     * 课程计划和媒资信息绑定
     *
     * @param bindTeachplanMediaDto 课程计划和媒资信息绑定参数
     */
    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        teachPlanService.associationMedia(bindTeachplanMediaDto);
    }
}
